import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

import 'common.dart';

class LoadingUtils {
  /// spinkit widget
  static Widget widget(BuildContext context, {Color? color, double? size}) {
    return SpinKitThreeBounce(
      color: color ?? Theme.of(context).primaryColor,
      size: size ?? 50.sp,
    );
  }

  /// loading tip
  static void show({String msg = '正在请求数据，请稍后...'}) {
    if (global.theme.value == ThemeStyle.dark.value) {
      EasyLoading.instance
        ..displayDuration = const Duration(milliseconds: 2000)
        ..indicatorType = EasyLoadingIndicatorType.circle
        ..loadingStyle = EasyLoadingStyle.light
        ..indicatorSize = 45.0
        ..radius = 10.0
        ..maskColor = Colors.blue.withOpacity(0.5)
        ..userInteractions = false
        ..dismissOnTap = false;
    } else {
      EasyLoading.instance
        ..displayDuration = const Duration(milliseconds: 2000)
        ..indicatorType = EasyLoadingIndicatorType.circle
        ..loadingStyle = EasyLoadingStyle.dark
        ..indicatorSize = 45.0
        ..radius = 10.0
        ..maskColor = Colors.black.withOpacity(0.5)
        ..userInteractions = false
        ..dismissOnTap = false;
    }
    EasyLoading.show(status: msg);
  }

  /// loading dismiss
  static void dismiss() {
    EasyLoading.dismiss();
  }
}
